package cn.tradewin.pmp.mixins;

import java.util.List;

import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.MixinAfter;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.beaneditor.PropertyModel;
import org.apache.tapestry5.corelib.components.Grid;

@MixinAfter
public class GridSortingDisabler {
	
	@InjectContainer
	private Grid grid;
	
	void setupRender() {
		if (grid.getDataSource().getAvailableRows() == 0) {
			return;
		}
		BeanModel<?> gridBeanModel = grid.getDataModel();
		List<String> properties = gridBeanModel.getPropertyNames();
		for (String property : properties) {
			PropertyModel propertyModel = gridBeanModel.get(property);
			propertyModel.sortable(false);
		}
	}
}
